package niit.group5.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainMenu extends Activity implements OnTouchListener {
	ImageView mbackground, mbackground2, mTitle;
	ImageView mButtonPlay, mButtonLoad, mButtonHelp, mButtonExit, mButtonSound;

	/** A handle to the thread that's actually running the animation. */
	// private GameThread mGameThread;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.mainmenu);

		mbackground = (ImageView) findViewById(R.id.background);
		mbackground.setBackgroundResource(R.drawable.background);
		mbackground2 = (ImageView) findViewById(R.id.background_2);
		mbackground2.setBackgroundResource(R.drawable.background_2);
		setLayout(mbackground2, 400, 50, -200, -100);

		mTitle = (ImageView) findViewById(R.id.img_title);
		mTitle.setBackgroundResource(R.drawable.cleanhouse);
		setLayout(mTitle, 100, 40, -160, -100);

		mButtonPlay = (ImageView) findViewById(R.id.btn_play);
		mButtonPlay.setBackgroundResource(R.drawable.btn_play);
		setLayout(mButtonPlay, 240, 120, -200, -300);
		mButtonPlay.setOnTouchListener(this);

		mButtonLoad = (ImageView) findViewById(R.id.btn_load);
		mButtonLoad.setBackgroundResource(R.drawable.btn_load);
		setLayout(mButtonLoad, 240, 180, -200, -300);
		mButtonLoad.setOnTouchListener(this);

		mButtonHelp = (ImageView) findViewById(R.id.btn_help);
		mButtonHelp.setBackgroundResource(R.drawable.btn_help);
		setLayout(mButtonHelp, 240, 240, -200, -300);
		mButtonHelp.setOnTouchListener(this);

		mButtonExit = (ImageView) findViewById(R.id.btn_exit);
		mButtonExit.setBackgroundResource(R.drawable.btn_exit);
		setLayout(mButtonExit, 240, 300, -200, -300);
		mButtonExit.setOnTouchListener(this);

		mButtonSound = (ImageView) findViewById(R.id.btn_sound);
		mButtonSound.setBackgroundResource(R.drawable.sound_on);
		setLayout(mButtonSound, 100, 340, -200, -300);
		mButtonSound.setOnTouchListener(this);

	}

	private void setLayout(View v, int left, int top, int right, int bottom) {
		RelativeLayout.LayoutParams privew = new RelativeLayout.LayoutParams(
				Math.round(v.getLayoutParams().width), Math.round(v
						.getLayoutParams().height));
		privew.setMargins(left, top, right, bottom);
		v.setLayoutParams(privew);
	}

	private void setSoundOnOff(boolean flgOn) {
		if (flgOn == true) {
			mButtonSound.setBackgroundResource(R.drawable.sound_on);
			// Music.play(getBaseContext(), resource);
			GameCleanHouseActivity.soundStatus = true;
		} else {
			mButtonSound.setBackgroundResource(R.drawable.sound_off);
			GameCleanHouseActivity.soundStatus = false;
		}
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		switch (v.getId()) {
		case R.id.btn_play:
			// mGameThread.doStart();
			startActivity(new Intent(getBaseContext(), GameLoader.class));
			finish();
			break;
		case R.id.btn_help:
			// mGameThread.doStart();
			startActivity(new Intent(getBaseContext(), Help.class));
			finish();
			break;
		case R.id.btn_exit:

			finish();
			break;
		case R.id.btn_sound:
			setSoundOnOff(!GameCleanHouseActivity.soundStatus);
			break;
		}
		// TODO Auto-generated method stub
		return false;
	}

}
